<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="线索电话" prop="phonenumber">
        <el-input v-model="queryParams.phonenumber" placeholder="请输入线索电话" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="意向等级" prop="intentionRankList">
        <el-select v-model="queryParams.intentionRankList" multiple clearable @keyup.enter.native="handleQuery">
          <el-option v-for="(item, index) in Enmu.intentionRank2" :key="index" :label="item.name"
            :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="预警等级" prop="warningStatusList">
        <el-select v-model="queryParams.warningStatusList" clearable multiple @keyup.enter.native="handleQuery">
          <el-option v-for="(item, index) in Enmu.warningStatus" :key="index" :label="item.name"
            :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="开始时间">
        <el-date-picker clearable v-model="queryParams.starTime" type="date" value-format="yyyy-MM-dd"
          placeholder="开始日期" @keyup.enter.native="handleQuery">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="录单员" prop="createName">
        <el-input v-model="queryParams.createName" placeholder="请输入录单员" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="微信/QQ" prop="relationWay">
        <el-input v-model="queryParams.relationWay" placeholder="请输入微信/QQ" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="线索状态" prop="clueStatusList">
        <el-select v-model="queryParams.clueStatusList" multiple clearable @keyup.enter.native="handleQuery">
          <el-option v-for="(item, index) in searchClueStatus" :key="index" :label="item.name"
            :value="item.value"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="分配状态" prop="status">
        <el-select v-model="queryParams.status" clearable @keyup.enter.native="handleQuery">
          <el-option label="待分配" :value="0"></el-option>
          <el-option label="已分配" :value="1"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="结束时间">
        <el-date-picker clearable v-model="queryParams.endTime" type="date" value-format="yyyy-MM-dd" placeholder="结束日期"
          @keyup.enter.native="handleQuery">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="业务员" prop="currentFollowupMan">
        <el-input v-model="queryParams.currentFollowupMan" placeholder="请输入业务员" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="车辆状态" prop="vehicleStatusList">
        <el-select v-model="queryParams.vehicleStatusList" clearable multiple>
          <el-option v-for="(item, index) in carStatus" :value="item" :label="item" :key="index"></el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item label="始发地" prop="originPlace">
        <provice-select isShowDistrict :key="isProvice" @changeValue="queryStartChangeValue"
          @keyup.enter.native="handleQuery"></provice-select>
      </el-form-item>
      <el-form-item label="目的地" prop="endProvince">
        <provice-select isShowDistrict :key="isProvice" @changeValue="queryEndChangeValue"
          @keyup.enter.native="handleQuery"></provice-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd('1')"
          v-hasPermi="['crm:clue:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-finished" size="mini" @click="allocation({}, '2')"
          v-hasPermi="['crm:clue:distribution']">分配</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="info" plain icon="el-icon-upload2" size="mini" @click="handleImport"
          v-hasPermi="['crm:clue:upload']">导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-upload2" size="mini" @click="handleExport"
          v-hasPermi="['crm:clue:download']">导出</el-button>
      </el-col>
      <el-tag style="margin-left: 10px">
        线索总数:{{ pageCount.clueSum }}
      </el-tag>
      <!-- <el-col :span="1.5">
        <el-button type="primary" plain size="mini" @click="queryParamsChange('dfp')">待分配:{{ pageCount.toBeAllocatedSum
          }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" plain size="mini" @click="queryParamsChange('yfp')">已分配:{{ pageCount.assignedSum
          }}</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="primary" plain size="mini" @click="queryParamsChange('wx')">无效:{{ pageCount.invalidSum
          }}</el-button>
      </el-col> -->
      <el-tag style="margin-left: 10px" @click="queryParamsChange('dfp')">
        待分配:{{ pageCount.toBeAllocatedSum }}
      </el-tag>
      <el-tag style="margin-left: 10px" @click="queryParamsChange('yfp')">
        已分配:{{ pageCount.assignedSum }}
      </el-tag>
      <el-tag style="margin-left: 10px" @click="queryParamsChange('wx')">
        无效申请:{{ pageCount.invalidSum }}
      </el-tag>
      <el-tag style="margin-left: 10px">
        已成交:{{ pageCount.alreadyTransactedSum }}
      </el-tag>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="clueList" :row-class-name="tableRowClassName"
      @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="线索姓名" align="center" prop="nickName" />
      <el-table-column label="姓名" align="center" prop="kzNickname" /> -->
      <el-table-column label="手机号" align="center" prop="phonenumber" width="120" />
      <el-table-column label="微信/QQ" align="center" prop="relationWay" />
      <!-- <el-table-column label="线索编号" align="center" prop="kznum" /> -->
      <el-table-column label="线索来源" align="center" prop="kznum">
        <template slot-scope="{ row }">
          {{ forrmatterEnmu(sourceWeb, row.sourceWeb) }}
        </template>
      </el-table-column>
      <el-table-column label="品牌/车型" align="center" prop="vehicleTypeOne"></el-table-column>
      <el-table-column label="车辆状态" align="center" prop="vehicleStatus"></el-table-column>
      <!-- <el-table-column label="车辆型号" align="center" prop="vehicleTypeTwo" /> -->
      <el-table-column label="始发地" align="center">
        <template slot-scope="{ row }">
          <!-- <span v-if="row.province || row.city">{{ fomatterAdressName(row.province) }} /
            {{ fomatterAdressName(row.city) }}
            <span v-if="row.region">/ {{ fomatterAdressName(row.region) }}</span></span> -->
          <!-- <span>{{ row.address }}</span>
          <span>{{ row.region1 }}</span> -->


          <span>{{ row.originPlaceDetailName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="目的地" align="center">
        <template slot-scope="{ row }">
          <!-- <span v-if="row.aimProvince || row.aimProvince">{{ fomatterAdressName(row.aimProvince) }} /
            {{ fomatterAdressName(row.aimCity) }}
            <span v-if="row.aimRegion">/ {{ fomatterAdressName(row.aimRegion) }}</span>
          </span> -->

          <!-- <span>{{ row.aim }}</span>
          <span>{{ row.aimRegion1 }}</span> -->

          <span>{{ row.aimPlaceDetailName }}</span>

        </template>
      </el-table-column>
      <el-table-column label="底价" align="center" prop="floorPrice" />
      <el-table-column label="报价" align="center" prop="price" />
      <el-table-column label="业务员" align="center" prop="currentFollowupMan" />
      <el-table-column label="录单员" align="center" prop="createName" />
      <el-table-column label="线索状态" align="center" prop="status">
        <template slot-scope="{ row }">
          <span v-if="row.clueStatus == '1'" style="color: red">战败申请</span>
          <span v-else>
            {{
              row.clueStatus == "5"
                ? ""
                : row.clueStatus == "6"
                  ? ""
                  : row.clueStatus == "8"
                    ? ""
                    : forrmatterEnmu(Enmu.clueStatus, row.clueStatus)
            }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="意向等级" align="center" prop="status">
        <template slot-scope="{ row }">
          <span v-if="!row.intentionRank && row.intentionRank != 0"></span>
          <span v-else>
            {{
              forrmatterEnmu(Enmu.intentionRank, row.intentionRank + '')
            }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="分配状态" align="center" prop="status">
        <template slot-scope="{ row }">
          {{ forrmatterEnmu(Enmu.followStatus, row.status) }}
        </template>
      </el-table-column>
      <el-table-column label="预警等级" align="center" prop="warningStatus">
        <template slot-scope="{ row }">
          <span v-if="row.warningStatus == 2">
            <el-tag type="" color="#0000ff" effect="dark" :hit="false">
              {{ forrmatterEnmu(Enmu.warningStatus, row.warningStatus) }}
            </el-tag>
          </span>
          <span v-else-if="row.warningStatus == 4">
            <el-tag type="" color="#FF7F00" effect="dark">
              {{ forrmatterEnmu(Enmu.warningStatus, row.warningStatus) }}
            </el-tag>
          </span>
          <span v-else-if="row.warningStatus == 3">
            <el-tag type="" color="#ff0000" effect="dark">
              {{ forrmatterEnmu(Enmu.warningStatus, row.warningStatus) }}
            </el-tag>
          </span>
          <span v-else-if="row.warningStatus == 1">
            <el-tag style="border: 0" type="" color="#F4A708" effect="dark">
              {{ forrmatterEnmu(Enmu.warningStatus, row.warningStatus) }}
            </el-tag>
          </span>
          <span v-else>
            <el-tag type="" effect="dark">
              {{ forrmatterEnmu(Enmu.warningStatus, row.warningStatus) }}
            </el-tag>
          </span>
        </template>
      </el-table-column>
      <el-table-column label="线索时间" align="center" prop="createTime">
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.createTime, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="{ row }">
          <el-button size="mini" type="text" @click="queryInfo(row)" v-if="row.clueStatus !== '3'"
            v-hasPermi="['crm:clue:check']">查看</el-button>
          <el-button size="mini" type="text" :disabled="row.status == 7" @click="allocation(row, 2)"
            v-if="row.clueStatus !== '3'" v-hasPermi="['crm:clue:distribution']">分配</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <detail-dialog :showDialog="showDetailDialog" :baseInfo="baseInfo" @close="close"
      :pageType="pageType"></detail-dialog>

    <el-dialog width="700px" :title="dialogFlag == '1' ? '新增' : '分配'" :visible.sync="innerVisible" append-to-body>
      <div>
        <el-form :model="addForm" ref="addForm" label-width="100px" :rules="addRules" v-if="dialogFlag == '1'">
          <el-form-item label="姓名" prop="kzNickname">
            <el-input style="width: 220px" v-model.trim="addForm.kzNickname" clearable placeholder="请输入姓名"></el-input>
          </el-form-item>
          <el-form-item label="电话" prop="kzphoneNumber">
            <el-input style="width: 220px" v-model.trim="addForm.kzphoneNumber" maxlength="11" minlength="11" clearable
              placeholder="请输入电话" show-word-limit></el-input>
          </el-form-item>
          <el-form-item label="微信/QQ" prop="relationWay">
            <el-input style="width: 220px" v-model.trim="addForm.relationWay" clearable
              placeholder="请输入微信/QQ"></el-input>
          </el-form-item>
          <el-form-item label="品牌/车型">
            <!-- <el-select v-model="addForm.vehicleTypeOne" style="width: 220px" clearable>
              <el-option v-for="(item, index) in Enmu.vehicleType" :value="item.name" :label="item.name"></el-option>
            </el-select> -->
            <el-input style="width: 220px" v-model.trim="addForm.vehicleTypeOne" clearable
              placeholder="请输入品牌/车型"></el-input>
          </el-form-item>
          <el-form-item label="车架/车牌号">
            <el-input style="width: 220px" v-model.trim="addForm.vin" clearable placeholder="多个车架/车牌号以逗号隔开"></el-input>
          </el-form-item>
          <el-form-item label="车辆状态">
            <el-select v-model="addForm.vehicleStatus" style="width: 220px" clearable>
              <el-option v-for="(item, index) in carStatus" :value="item" :label="item" :key="index"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="始发地">
            <provice-select :defaultCity="defaultCity" isShowDistrict @changeValue="addStartChangeValue"
              :inputWidth="150"></provice-select>
          </el-form-item>
          <el-form-item label="目的地">
            <provice-select :defaultCity="defaultAimCity" isShowDistrict @changeValue="addEndChangeValue"
              :inputWidth="150"></provice-select>
          </el-form-item>
          <el-form-item label="线索来源">
            <el-select v-model="addForm.sourceWeb" style="width: 220px" clearable>
              <el-option v-for="(item, index) in sourceWeb" :value="item.value" :label="item.name"
                :key="index"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="平台订单编号" prop="orderNumber">
            <el-input style="width: 220px" v-model="addForm.orderNumber" clearable></el-input>
          </el-form-item>
          <el-form-item label="平台定金" prop="earnest">
            <el-input style="width: 220px" v-model="addForm.earnest" clearable></el-input>
          </el-form-item>
          <!-- <el-form-item label="分配模式" prop="type" v-if="isTrue">
            <el-select v-model="addForm.type" style="width: 220px" clearable>
              <el-option value="1" label="手动分配" v-if="isItemTrue"></el-option>
              <el-option value="2" label="自动分配"></el-option>
            </el-select>
          </el-form-item> -->
          <el-form-item label="销售员列表" v-if="addForm.type == '1'" prop="currentFollowupMan">
            <el-select v-model="addForm.currentFollowupMan" style="width: 220px" clearable>
              <el-option v-for="(item, index) in marketList" :key="index" :value="item" :label="item"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <el-form :inline="true" label-width="100px" v-if="dialogFlag == '2'">
          <el-form-item label="销售员列表">
            <el-select v-model="selectMarketIds" style="width: 220px" clearable>
              <el-option v-for="(item, index) in marketList" :key="index" :value="item" :label="item"></el-option>
            </el-select>
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" :loading="true" v-if="isLoading">加载中...</el-button>
        <el-button type="primary" v-else @click="submitForm">确定</el-button>
        <el-button @click="innerVisible = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload ref="upload" :limit="1" accept=".xlsx, .xls" :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport" :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress" :on-success="handleFileSuccess" :auto-upload="false" :data="{
          type: upload.type,
          currentFollowupMan: upload.currentFollowupMan,
        }" drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" />
            是否更新已经存在的数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <!-- <el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline"
            @click="importTemplate">下载模板</el-link> -->
          <a href="https://dycrm.fanshucar.cn/prod-api/profile/upload/CRM导入表格.xlsx " style="color: #1890ff">下载模版</a>
        </div>
      </el-upload>
      <el-form :model="upload" :rules="uploadRules" size="mini" label-width="100px" style="margin-top: 15px"
        ref="uploadForm">
        <el-form-item label="分配模式" prop="type">
          <el-select v-model="upload.type" clearable>
            <el-option value="1" label="手动分配"></el-option>
            <el-option value="2" label="自动分配"></el-option>
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="销售员列表" v-if="upload.type == '1'" prop="currentFollowupMan">
                    <el-select v-model="upload.currentFollowupMan" clearable>
                        <el-option v-for="item,index in marketList" :key="index" :value="item" :label="item"></el-option>
                    </el-select>
                </el-form-item> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listClueLibrary,
  addClue,
  getMarketList,
  manualDistribution,
  importClueList,
  getCountDetail,
  getRecordPersonnel,
} from "@/api/crm/clueLibrary";
import { getInfo } from "@/api/login.js";
import { listData } from "@/api/system/dict/data.js";
import DetailDialog from "./detailDialog.vue";
import ProviceSelect from "@/components/ProviceSelect/index.vue";
import Enmu from "@/utils/enmu.js";
import { forrmatterEnmu } from "@/utils/index";
import { mapGetters } from "vuex";
import { getToken } from "@/utils/auth";
export default {
  name: "Clue",
  data() {
    return {
      headers: {
        Authorization: "Bearer " + getToken(),
      },
      // 显示搜索条件
      showSearch: true,
      // 非单个禁用
      single: true,
      ids: [],
      // 非多个禁用
      multiple: true,
      Enmu,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        kznum: null,
        phonenumber: null,
        province: null,
        city: null,
        aimProvince: null,
        aimCity: null,
        currentFollowupMan: null,
        status: null,
        starTime: null,
        endTime: null,
        clueStatus: null,
        createName: null,
        flag: null,
        warningStatusList: [],
        vehicleStatusList: [],
        relationWay: null,
        intentionRankList: null,
      },
      baseInfo: {},
      showDetailDialog: false,
      innerVisible: false,
      addForm: {},
      loading: false,
      clueList: [],
      total: 0,
      defaultAimCity: {},
      defaultCity: {},
      // 1 新增  2 分配
      dialogFlag: "",
      allocationClueId: [],
      marketList: [],
      selectMarketIds: "",
      fileList: [],
      uploadDialog: false,
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/clue/admin/batchImportClue",
        type: null,
        currentFollowupMan: null,
      },
      roles: [],
      isTrue: true,
      isItemTrue: true,
      pageCount: {},
      // carStatus: [
      //   '正常车辆', '油车/燃油亏损', '油车/电量亏损', '电车/电量亏损', '事故车', '证件缺失', '纠纷车'
      // ],
      carStatus: [
        "新车",
        "二手车",
        "燃油车",
        "新能源",
        // "正常车辆",
        "故障车",
        "抵押车",
        "亏油",
        "亏电",
        // "油电亏损车辆",
        "非常规车辆（三轮车、摩托车、改装车、商用车、超尺寸车辆）",
      ],
      sourceWeb: [],
      isProvice: true,
      isLdryxs: false,
      pageType: "1",
      isLoading: false,
      searchClueStatus: [
        {
          value: "1",
          name: "战败申请",
        },
        {
          value: "2",
          name: "无效申请",
        },
        // {
        //   value: "4",
        //   name: "确认战败",
        // },
        // {
        //   value: "7",
        //   name: "确认无效",
        // },
      ],
      // rules: {
      //   kzNickname: [
      //     { required: true, message: '请输入姓名', trigger: 'blur' },
      //   ]
      // }
    };
  },
  components: { DetailDialog, ProviceSelect },
  async created() {
    await this.getUserInfo();
    this.listMarket();
    this.getSourceList();
    this.getList();
  },
  computed: {
    ...mapGetters(["allCityList"]),
    addRules() {
      let rules = {
        /* kzphoneNumber: [
          { required: true, message: "请输入手机号", trigger: "blur" },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur",
          },
        ], */
        type: [
          { required: true, message: "请选择分配模式", trigger: "change" },
        ],
        currentFollowupMan: [
          { required: true, message: "请选择销售员", trigger: "change" },
        ],
      };
      if (this.addForm.type == "1") {
        return rules;
      }
      // return {
      //   kzphoneNumber: rules.kzphoneNumber,
      //   type: rules.type,
      // };
      return rules;
    },
    uploadRules() {
      let rules = {
        type: [
          { required: true, message: "请选择分配模式", trigger: "change" },
        ],
        // currentFollowupMan: [
        //     { required: true, message: '请选择销售员', trigger: 'change' }
        // ]
      };
      if (this.upload.type == "1") {
        return rules;
      }
      return {
        type: rules.type,
      };
    },
  },
  methods: {
    forrmatterEnmu,
    // 获取用户信息
    getUserInfo() {
      getInfo().then((res) => {
        if (res.code !== 200) return;
        this.roles = res.roles;
        res.roles.forEach((item) => {
          if (item == "05") {
            this.isTrue = false;
          }
          if (item == "11") {
            this.isTrue = true;
            this.isItemTrue = false;
          }
          if (item == "ldryxs") {
            this.isLdryxs = true;
          }
        });
      });
      return getInfo();
    },
    // 查询字典数据
    getSourceList() {
      listData({
        pageNum: 1,
        pageSize: 10,
        dictType: "client_source",
      }).then((res) => {
        if (res.code == 200) {
          this.sourceWeb = res.rows.map((item) => {
            return {
              value: item.dictValue,
              name: item.dictLabel,
            };
          });
        }
      });
    },
    // 省市区转换成中文
    fomatterAdressName(code) {
      let index = this.allCityList.findIndex((ele) => ele.id == code);
      return index > -1 ? this.allCityList[index].cityName : code;
    },
    queryStartChangeValue(values) {
      this.queryParams.province = values[0];
      this.queryParams.city = values[1];
      this.queryParams.region = values[2];
    },
    queryEndChangeValue(values) {
      this.queryParams.aimProvince = values[0];
      this.queryParams.aimCity = values[1];
      this.queryParams.aimRegion = values[2];
    },
    addStartChangeValue(values) {
      this.addForm.province = values[0];
      this.addForm.city = values[1];
      this.addForm.region = values[2];
    },
    addEndChangeValue(values) {
      this.addForm.aimProvince = values[0];
      this.addForm.aimCity = values[1];
      this.addForm.aimRegion = values[2];
    },
    queryInfo(row) {
      this.showDetailDialog = true;
      this.baseInfo = { ...row };
      if (row.clueStatus == "5" || row.clueStatus == "6" || row.clueStatus == "8") {
        this.pageType = "1";
      } else {
        this.pageType = "3";
      }
    },
    queryParamsChange(type) {
      switch (type) {
        case "dfp":
          this.queryParams.clueStatus = "5";
          break;
        case "yfp":
          this.queryParams.clueStatus = "6";
          break;
        case "wx":
          this.queryParams.clueStatus = "2";
          break;

        default:
          break;
      }
      this.getList();
    },
    tableRowClassName({ row, rowIndex }) {
      if (row.flag == 1) {
        console.log(row, 888);
        return 'warning-row';
      } else {
        return '';
      }
    },
    // 获取统计信息
    getCountInfo() {
      if (this.isLdryxs) this.queryParams.flag = "666";
      getCountDetail(this.queryParams).then((res) => {
        if (res.code == 200) {
          this.pageCount = res.data;
        }
      });
    },
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.getCountInfo();
      this.loading = true;
      const index = this.roles.findIndex((item) => item == "ldryxs");
      if (this.isLdryxs) {
        getRecordPersonnel(this.queryParams).then((response) => {
          this.clueList = response.rows;
          this.total = response.total;
          this.loading = false;

          this.clueList.forEach(element => {

            let province = element.province ? this.fomatterAdressName(element.province) : ''
            let city = element.city ? '/' + this.fomatterAdressName(element.city) : ''
            element.address = province + city

            let aimProvince = element.aimProvince ? this.fomatterAdressName(element.aimProvince) : ''
            let aimCity = element.aimCity ? this.fomatterAdressName(element.aimCity) : ""

            element.aim = aimProvince + '/' + aimCity
            if (element.region) {
              element.region1 = '/' + this.fomatterAdressName(element.region)
            }
            if (element.aimRegion) {
              element.aimRegion1 = '/' + this.fomatterAdressName(element.aimRegion)
            }
          });

          console.log(this.clueList, 'clueList');


        });



      } else {
        listClueLibrary(this.queryParams).then((response) => {
          this.clueList = response.rows;
          this.total = response.total;
          this.loading = false;

          this.clueList.forEach(element => {

            let province = element.province ? this.fomatterAdressName(element.province) : ''
            let city = element.city ? '/' + this.fomatterAdressName(element.city) : ''
            element.address = province + city

            let aimProvince = element.aimProvince ? this.fomatterAdressName(element.aimProvince) : ''
            let aimCity = element.aimCity ? '/' + this.fomatterAdressName(element.aimCity) : ""

            element.aim = aimProvince + aimCity
            if (element.region) {
              element.region1 = '/' + this.fomatterAdressName(element.region)
            }
            if (element.aimRegion) {
              element.aimRegion1 = '/' + this.fomatterAdressName(element.aimRegion)
            }
          });


          console.log(this.clueList, 'clueList1');

        });




      }


    },
    close() {
      this.showDetailDialog = false;
      this.getList();
    },
    handleAdd(index) {
      this.resetQueryForm();
      this.innerVisible = true;
      this.dialogFlag = index;
      this.defaultAimCity = {};
      this.defaultCity = {};
    },
    resetQueryForm() {
      this.addForm = {
        kzNickname: null,
        kzphoneNumber: null,
        vehicleTypeOne: null,
        sourceWeb: null,
        province: null,
        city: null,
        region: null,
        aimProvince: null,
        aimCity: null,
        aimRegion: null,
        type: null,
        currentFollowupMan: null,
        vin: null,
      };
    },
    submitForm() {
      this.isLoading = true
      if (this.dialogFlag == "1") {
        this.$refs["addForm"].validate((valid) => {
          if (valid) {
            addClue(this.addForm).then((res) => {
              if (res.code == 200) {
                this.$modal.msgSuccess("新增成功");
                this.innerVisible = false;
                this.getList();
              }
              this.isLoading = false
            }).catch(res => {
              this.isLoading = false
            })
          }
        });
      } else if (this.dialogFlag == "2") {
        manualDistribution({
          clueIdList: this.allocationClueId,
          currentFollowupMan: this.selectMarketIds,
        }).then((res) => {
          if (res.code == 200) {
            this.$modal.msgSuccess("分配成功");
            this.innerVisible = false;
            this.getList();
          }
          this.isLoading = false
        }).catch(res => {
          this.isLoading = false
        })
      }
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams = {};
      this.isProvice = !this.isProvice;
      this.handleQuery();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "/clue/admin/exportSelect",
        {
          ...this.queryParams,
        },
        `clue_${new Date().getTime()}.xlsx`
      );
    },
    allocation(row, index) {
      if (!row.clueId) {
        if (this.ids.length <= 0) {
          this.$modal.msgWarning("请先选择线索");
          return;
        } else {
          this.allocationClueId = this.ids;
        }
      } else {
        this.allocationClueId = [row.clueId];
      }
      this.innerVisible = true;
      this.dialogFlag = index;
    },
    // 获取业务员员列表
    listMarket() {
      getMarketList().then((res) => {
        this.marketList = res.data;
      });
    },
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.clueId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    handlePreview(file) {
      console.log(file);
    },
    handleUpload() {
      this.uploadDialog = true;
    },
    uploadSuccess() {
      this.$modal.msgSuccess("上传成功");
      this.uploadDialog = false;
      this.getList();
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "用户导入";
      this.upload.open = true;
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs["uploadForm"].validate((valid) => {
        if (valid) {
          this.$refs.upload.submit();
        }
      });
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download(
        "system/user/importTemplate",
        {},
        `clue_template_${new Date().getTime()}.xlsx`
      );
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(
        "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
        response.msg +
        "</div>",
        "导入结果",
        { dangerouslyUseHTMLString: true }
      );
      this.getList();
    },
  },
};
</script>
<style lang="scss" scoped>
.row-between {
  display: flex;
  flex-flow: row nowrap;
  justify-content: space-between;
}

::v-deep .el-timeline-item__node {
  background-color: #02a7f0 !important;
}

::v-deep .el-timeline-item__tail {
  position: absolute;
  left: 4px;
  height: 100%;
  border-left: 2px solid #02a7f0;
}

::v-deep .el-table .warning-row {
  background: oldlace;
}
</style>